/*
 * @Author: 十二 1725060993@qq.com
 * @Date: 2024-03-22 21:52:59
 * @LastEditors: 十二 1725060993@qq.com
 * @LastEditTime: 2024-05-19 21:00:52
 * @FilePath: \02-Fundamentals-Part-2\starter\script.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
'use strict';
// let firstNanme = 10;
// console.log(firstNanme);

// function f() {
//   console.log("hello!");

// }

// //匿名函数，没有名字，必须要进行存储
// const age = function (birthYear) {
//   return 2024 - birthYear;
// }
// //调用匿名函数,此时age就是该函数的名字

// console.log(age(2002));

// //箭头函数,birthYear是传入的参数，箭头后面的是表达式
// const age1 = birthYear => 2024 - birthYear;
// console.log(age1(2003));

// //如果表达式语句不止一个，则需要花括号
// //计算退休年龄
// const yearsUntilRetirement = (birthYear, firstNanme) => {
//   const age2 = 2024 - birthYear;
//   const retirement = 60 - age2;
//   return `${firstNanme}的退休年龄是${retirement}`;
// }

// console.log(yearsUntilRetirement(2002, 'lijingjing'))
// let a = "1";
// let b = 1;
// console.log(a !== b)

// const friends = ['jhon', 'mary', 'helen', 1990];
// friends[2] = "hh";
// friends.pop();
// console.log(friends);

// const years = new Array(1990, 1999, 2002);

// let months = new Array(5);

// months = [1, 2, 3];
// console.log(months);

// //取出数组中的数据
// console.log(years[0]);


//一个对象的定义
const people = {
  firstName: 'jing',
  lastName: 'li',
  birthYear: 2002,
  job: 'student',
  friends: ['mary', 'milan'],
  driverLicense: false,
  //可以this访问对象中的所有属性
  calAge: function () {
    return 2024 - this.birthYear;
  },
}

let temp = 'firstName';
console.log(people[temp]);
console.log(`${people['firstName']} has ${people.friends.length} friends,and his besr friends is ${people.friends[0]}.`)

console.log(people.calAge());

let output = `${people.firstName} is a ${people.calAge()}-year old ${people.job},and she has`;
if (people.driverLicense) {
  console.log(output + ' a driverLicense.');
} else {
  console.log(output + ' no driverLicense');
}

const Mark = {
  fullName: 'Mark',
  weight: 78,
  height: 1.69,
  calcBMI: function () {
    this.bmi = this.weight / this.height ** 2;
    return this.bmi;
  }
}

const Jhon = {
  fullName: 'Jhon',
  weight: 92,
  height: 1.95,
  calcBMI: function () {
    this.bmi = this.weight / this.height ** 2;
    return this.bmi;
  }
}
//必须要调用一次calcBMI才可以给对象添加bmi这个属性值
if (Mark.calcBMI() > Jhon.calcBMI()) {
  console.log(`Mark\'s BMI (${Mark.bmi}) is higher than Jhon\'BMI (${Jhon.bmi})!`)
} else {
  console.log(`Jhon\'BMI (${Jhon.bmi}) is higher than Mark\'s BMI (${Mark.bmi})!`)
}


